<template>
	<view class="goods_list">
		<goods-list :goods="goods" @goodsItemClick="goGoodsDetail"></goods-list>
		<view class="isOver" v-if="flag">
			-----我是有底线的-----
		</view>
	</view>
</template>

<script>
	import goodsList from '../../components/goods-list/goods-list.vue'
	export default {
		components:{"goods-list":goodsList},
		data() {
			return {
				pageindex:1,
				goods:[],
				flag:false,
			}
		},
		onLoad() {
			this.getGoodsList()
		},
		onReachBottom() { 
			if(this.goods.length=2){ return this.flag =true}
			console.log('触底了');
			this.pageindex++;
			this.getGoodsList()
		},
		onPullDownRefresh() {
			this.pageindex = 1
			this.goods=[]
			this.flag = false
			setTimeout(()=>{
				this.getGoodsList(()=>{
					uni.stopPullDownRefresh()
				})
			},1000)
		},
		methods: {
			// 获取商品列表的数据
			getGoodsList(callback){
				this.$myRequest({
					url:'/getHotGoods.json?pagenum='+this.pageindex,	
				}).then(res=>{
					console.log(res.data)
					this.goods = [...this.goods,...res.data.message.goods]
					// console.log(this.goods)
				})
				callback&&callback()
			},
			// 导航到商品详情页
			goGoodsDetail(id){
				uni.navigateTo({
					url:"/pages/goods-detail/goods-detail?id="+id
				})
				console.log(id)
			}
		}
	}
</script>

<style lang="scss">
		.goods_list{
			background: #eee;
		}
		.isOver{
			width: 100%;
			height: 50px;
			line-height: 50px;
			text-align: center;
			font-size: 28rpx;
		}
</style>
